package springapp.web.utils;

import org.springframework.ui.ModelMap;
import org.springframework.web.servlet.ModelAndView;

/**
 * @author sad
 */
public class MV extends ModelAndView {

    public MV(String viewName, Object... attributes) {
        super(viewName);
        if (attributes.length == 0) {
            return;
        }
        if (attributes.length % 2 != 0) {
            throw new IllegalArgumentException("Attributes should be array of pairs [name,value]");
        }
        ModelMap map = getModelMap();
        for (int i = 0; i < attributes.length; i += 2) {
            map.addAttribute((String) attributes[i], attributes[i + 1]);
        }
    }
}
